﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSWS.Commonality
{
    /// <summary>
    /// 铭感词过滤
    /// </summary>
    public static class FilterWords
    {
        /// <summary>
        /// 判断字符串中是否有敏感词
        /// </summary>
        /// <param name="filterWords">需要判断的字符串</param>
        /// <returns>有敏感词返回true，无敏感词返回false</returns>
        public static bool GetFilterWords(string filterWords)
        {
            bool isResult = false;
            string strFullPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "SensitiveWordDic.txt";
            List<string> listStr = ReadTxt.GetListForTxt(strFullPath);
            if (listStr == null || listStr.Count == 0)
            {
                isResult = false;   //如果没有设置敏感词字典，则认为是不违反规则
            }
            else
            {
                for (int i = 0; i < listStr.Count; i++)
                {
                    if (filterWords.IndexOf(listStr[i]) > -1)
                    {
                        isResult = true;
                        break;
                    }
                }
            }
            return isResult;
        }
    }
}
